using System;
using BitMango.Diagnostics;
using UnityEngine;
using UnityEngine.UI;

public class IndicatorWithMessage : MonoBehaviour
{
	public string Text
	{
		get
		{
			return this.message.text;
		}
		set
		{
			Debugger.Assert(this.message != null, "IndicatorWithMessage.Text : Message is null.");
			this.message.text = value;
		}
	}

	private void Awake()
	{
		if (this.message != null)
		{
			return;
		}
		GameObject gameObject = new GameObject("Panel");
		RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
		rectTransform.SetParent(base.GetComponent<RectTransform>(), false);
		rectTransform.pivot = Vector2.one * 0.5f;
		rectTransform.anchorMin = Vector2.zero;
		rectTransform.anchorMax = Vector2.one;
		rectTransform.offsetMin = Vector2.zero;
		rectTransform.offsetMax = Vector2.zero;
		gameObject.AddComponent<CanvasRenderer>();
		Image image = gameObject.AddComponent<Image>();
		image.color = new Color(0f, 0f, 0f, 0.8f);
		GameObject gameObject2 = new GameObject("Text");
		RectTransform rectTransform2 = gameObject2.AddComponent<RectTransform>();
		rectTransform2.SetParent(rectTransform, false);
		rectTransform2.pivot = Vector2.one * 0.5f;
		rectTransform2.anchorMin = new Vector2(0f, 0.5f);
		rectTransform2.anchorMax = new Vector2(1f, 0.5f);
		gameObject2.AddComponent<CanvasRenderer>();
		this.message = gameObject2.AddComponent<Text>();
		this.message.font = (Resources.Load("SystemFont") as Font);
		this.message.alignment = TextAnchor.MiddleCenter;
		this.message.resizeTextForBestFit = true;
		this.message.resizeTextMaxSize = 30;
		this.message.color = Color.white;
		// Handheld.SetActivityIndicatorStyle(AndroidActivityIndicatorStyle.Large);
	}

	public static void Show(string message)
	{
		if (IndicatorWithMessage.instance == null)
		{
			IndicatorWithMessage.Initialize();
		}
		IndicatorWithMessage.instance.gameObject.SetActive(true);
		IndicatorWithMessage.instance.Text = message;
		Handheld.StartActivityIndicator();
	}

	public static void Hide()
	{
		if (IndicatorWithMessage.instance == null)
		{
			IndicatorWithMessage.Initialize();
		}
		Handheld.StopActivityIndicator();
		IndicatorWithMessage.instance.gameObject.SetActive(false);
	}

	private static void Initialize()
	{
		if (IndicatorWithMessage.instance != null)
		{
			return;
		}
		GameObject gameObject = new GameObject("__IndicatorWithMessage__");
		gameObject.AddComponent<RectTransform>();
		Canvas canvas = gameObject.AddComponent<Canvas>();
		canvas.renderMode = RenderMode.ScreenSpaceOverlay;
		IndicatorWithMessage.instance = gameObject.AddComponent<IndicatorWithMessage>();
	}

	private static IndicatorWithMessage instance;

	private Text message;
}
